package com.ztesoft.huangfu.learning.springboot.springboottransaction.service.impl;

import com.github.pagehelper.PageHelper;
import com.ztesoft.huangfu.learning.springboot.springboottransaction.dao.UserDao;
import com.ztesoft.huangfu.learning.springboot.springboottransaction.entity.User;
import com.ztesoft.huangfu.learning.springboot.springboottransaction.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * Author: huangfu.daohui
 * Date: 2018/5/23
 * Time: 22:44
 * Version: 1.0
 * Description:
 **/

@Service
@Transactional(rollbackFor = {RuntimeException.class, Exception.class})
public class UserServiceImpl implements UserService {

    @Autowired
    private UserDao userDao;

    @Override
    public int addUser(User user) {
        return userDao.addUser(user);
    }

    @Override
    public int delete(String id) {
        return userDao.delete(id);
    }

    @Override
    public int update(User user) {
        return userDao.update(user);
    }

    @Override
    public List<User> selectUsers(int pageNum, int pageSize) {
        //使用分页插件,核心代码就这一行
        PageHelper.startPage(pageNum, pageSize);
        List<User> userList = userDao.selectUsers(pageNum, pageSize);
        return userList;
    }

    @Override
    public User selectUserById(String id) {
        return userDao.selectUserById(id);
    }



}
